<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <meta name="baidu-site-verification" content="code-OyDaGkZ9eq">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Gemini","version":"7.8.0","exturl":true,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":"mac"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":true,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="1. 标准表达式语法1.1 简介Thymeleaf 是一个服务器端 Java 模板引擎，能够处理 HTML、XML、CSS、JAVASCRIPT 等模板文件。Thymeleaf 模板可以直接当作静态原型来使用，它主要目标是为开发者的开发工作流程带来优雅的自然模板，也是 Java 服务器端 HTML5 开发的理想选择。">
<meta property="og:type" content="article">
<meta property="og:title" content="thymeleaf 使用">
<meta property="og:url" content="http://example.com/2021/01/03/%E5%B0%8F%E7%94%9F%E5%8D%9A%E5%AE%A2/java/thymeleaf%E6%96%87%E6%A1%A3/index.html">
<meta property="og:site_name" content="极风键客">
<meta property="og:description" content="1. 标准表达式语法1.1 简介Thymeleaf 是一个服务器端 Java 模板引擎，能够处理 HTML、XML、CSS、JAVASCRIPT 等模板文件。Thymeleaf 模板可以直接当作静态原型来使用，它主要目标是为开发者的开发工作流程带来优雅的自然模板，也是 Java 服务器端 HTML5 开发的理想选择。">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2021-01-03T12:46:25.000Z">
<meta property="article:modified_time" content="2021-02-17T07:38:28.520Z">
<meta property="article:author" content="王增明">
<meta property="article:tag" content="java">
<meta property="article:tag" content="spring">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://example.com/2021/01/03/%E5%B0%8F%E7%94%9F%E5%8D%9A%E5%AE%A2/java/thymeleaf%E6%96%87%E6%A1%A3/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'en'
  };
</script>

  <title>thymeleaf 使用 | 极风键客</title>
  


  <script data-pjax>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?b94f963e94e4127fa71ab49cbddce93b";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="极风键客" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">极风键客</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">技术狂热爱好者!</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL3dhbmd6ZW5nbWluZw==" title="客官,来嘛~" aria-label="客官,来嘛~"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/01/03/%E5%B0%8F%E7%94%9F%E5%8D%9A%E5%AE%A2/java/thymeleaf%E6%96%87%E6%A1%A3/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpeg">
      <meta itemprop="name" content="王增明">
      <meta itemprop="description" content="喜欢折腾的极客聚集地.">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="极风键客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          thymeleaf 使用
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-01-03 20:46:25" itemprop="dateCreated datePublished" datetime="2021-01-03T20:46:25+08:00">2021-01-03</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-02-17 15:38:28" itemprop="dateModified" datetime="2021-02-17T15:38:28+08:00">2021-02-17</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/java/" itemprop="url" rel="index"><span itemprop="name">java</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>22k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>20 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="1-标准表达式语法"><a href="#1-标准表达式语法" class="headerlink" title="1. 标准表达式语法"></a>1. 标准表达式语法</h2><h3 id="1-1-简介"><a href="#1-1-简介" class="headerlink" title="1.1 简介"></a>1.1 简介</h3><p>Thymeleaf 是一个服务器端 Java 模板引擎，能够处理 HTML、XML、CSS、JAVASCRIPT 等模板文件。Thymeleaf 模板可以直接当作静态原型来使用，它主要目标是为开发者的开发工作流程带来优雅的自然模板，也是 Java 服务器端 HTML5 开发的理想选择。</p>
<a id="more"></a>


<h3 id="1-2-引入"><a href="#1-2-引入" class="headerlink" title="1.2 引入"></a>1.2 引入</h3><p>创建一个 HTML 模板文件：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">HTML</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">xmlns:th</span>=<span class="string">&quot;http://www.thymeleaf.org&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">head</span>&gt;</span>    </span><br><span class="line">        <span class="tag">&lt;<span class="name">title</span>&gt;</span>Index Page<span class="tag">&lt;/<span class="name">title</span>&gt;</span>    </span><br><span class="line">        <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;Content-Type&quot;</span> <span class="attr">content</span>=<span class="string">&quot;text/html; charset=UTF-8&quot;</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">body</span>&gt;</span>    </span><br><span class="line">        <span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;message&#125;&quot;</span>&gt;</span>Welcome to BeiJing!<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>通过<code>&lt;html xmlns:th=&quot;http://www.thymeleaf.org&quot;&gt;</code>引入 Thymeleaf 命名空间。<code>th:text</code>用于处理<code>p</code>标签体的文本内容。该模板文件直接在任何浏览器中正确显示，浏览器会自动忽略它们不能理解的属性<code>th:text</code>。但这不是一个真正有效的 HTML5 文档，因为 HTML5 规范是不允许使用<code>th:*</code>这些非标准属性的。我们可以切换到 Thymeleaf 的<code>data-th-*</code>语法，以此来替换<code>th:*</code>语法：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">HTML</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">xmlns:th</span>=<span class="string">&quot;http://www.thymeleaf.org&quot;</span></span></span><br><span class="line">	&lt;head&gt;    </span><br><span class="line">		<span class="tag">&lt;<span class="name">title</span>&gt;</span>Index Page<span class="tag">&lt;/<span class="name">title</span>&gt;</span>    </span><br><span class="line">		<span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;Content-Type&quot;</span> <span class="attr">content</span>=<span class="string">&quot;text/html; charset=UTF-8&quot;</span> /&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">head</span>&gt;</span>	</span><br><span class="line">	<span class="tag">&lt;<span class="name">body</span>&gt;</span>    </span><br><span class="line">		<span class="tag">&lt;<span class="name">p</span> <span class="attr">data-th-text</span>=<span class="string">&quot;$&#123;message&#125;&quot;</span>&gt;</span>Welcome to BeiJing!<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>HTML5 规范是允许<code>data-*</code>这样自定义的属性的。<code>th:*</code>和<code>data-th-*</code>这两个符号是完全等效且可以互换的。但为了简单直观和代码的紧凑性，本文采用<code>th:*</code>的表示形式。</p>
<h2 id="2-标准表达式语法"><a href="#2-标准表达式语法" class="headerlink" title="2. 标准表达式语法"></a>2. 标准表达式语法</h2><p>Thymeleaf 提供了非常丰富的标准表达式语法，总共有 8 大类：</p>
<ul>
<li>简单表达式</li>
<li>字面值</li>
<li>文本操作</li>
<li>算术运算</li>
<li>布尔运算</li>
<li>比较和相等</li>
<li>条件运算</li>
<li>无操作符</li>
</ul>
<h3 id="2-1-简单表达式"><a href="#2-1-简单表达式" class="headerlink" title="2.1 简单表达式"></a>2.1 简单表达式</h3><table>
<thead>
<tr>
<th align="center">语法</th>
<th align="center">名称</th>
<th align="center">描述</th>
<th align="center">作用</th>
</tr>
</thead>
<tbody><tr>
<td align="center">${…}</td>
<td align="center">Variable Expressions</td>
<td align="center">变量表达式</td>
<td align="center">取出上下文变量的值</td>
</tr>
<tr>
<td align="center">*{…}</td>
<td align="center">Selection Variable Expressions</td>
<td align="center">选择变量表达式</td>
<td align="center">取出选择的对象的属性值</td>
</tr>
<tr>
<td align="center">#{…}</td>
<td align="center">Message Expressions</td>
<td align="center">消息表达式</td>
<td align="center">使文字消息国际化，I18N</td>
</tr>
<tr>
<td align="center">@{…}</td>
<td align="center">Link URL Expressions</td>
<td align="center">链接表达式</td>
<td align="center">用于表示各种超链接地址</td>
</tr>
<tr>
<td align="center">~{…}</td>
<td align="center">Fragment Expressions</td>
<td align="center">片段表达式</td>
<td align="center">引用一段公共的代码片段</td>
</tr>
</tbody></table>
<h4 id="2-1-1-…"><a href="#2-1-1-…" class="headerlink" title="2.1.1 ${…}"></a>2.1.1 ${…}</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@GetMapping(&quot;/standard-expression-syntax/variables&quot;)</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> String <span class="title">variables</span><span class="params">(ModelMap model, HttpSession session)</span> </span>&#123;    </span><br><span class="line">    model.put(<span class="string">&quot;now&quot;</span>, <span class="keyword">new</span> Date());    </span><br><span class="line">    model.put(<span class="string">&quot;message&quot;</span>, <span class="string">&quot;Welcome to BeiJing!&quot;</span>);    </span><br><span class="line">    session.setAttribute(<span class="string">&quot;user&quot;</span>, <span class="keyword">new</span> User(<span class="string">&quot;fanlychie&quot;</span>, <span class="string">&quot;男&quot;</span>, <span class="number">24</span>));   </span><br><span class="line">    ... ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>通过变量表达式<code>$&#123;&#125;</code>取出上下文环境中的<code>message</code>变量：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- Welcome to BeiJing! --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;message&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>它相当于：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ctx.getVariable(&quot;message&quot;);</span><br></pre></td></tr></table></figure>
<h4 id="2-1-2-…"><a href="#2-1-2-…" class="headerlink" title="2.1.2 *{…}"></a>2.1.2 *{…}</h4><p>变量表达式<code>$&#123;&#125;</code>是面向整个上下文的，而选择变量表达式<code>*&#123;&#125;</code>的上下文是父标签（<code>th:object</code>）所选择的对象：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">th:object</span>=<span class="string">&quot;$&#123;session.user&#125;&quot;</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;*&#123;name&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;*&#123;sex&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;*&#123;age&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>它相当于：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;session.user.name&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;session.user.sex&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;session.user.age&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>如果对象没有被选择，那么，<code>*&#123;&#125;</code>和<code>$&#123;&#125;</code>表达式所达到的效果是完全相同的：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;*&#123;session.user.name&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;session.user.name&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="2-1-3-…"><a href="#2-1-3-…" class="headerlink" title="2.1.3 #{…}"></a>2.1.3 #{…}</h4><p>消息表达式可用于国际化文字信息。首先我们来了解一下 i18n 资源文件的命名规则：</p>
<ul>
<li>basename.properties</li>
<li>basename_language.properties</li>
<li>basename_language_country.properties</li>
</ul>
<p><code>basename</code>是自定义的资源文件名称，<code>language</code>和<code>country</code>必须是 Java 支持的语言和国家。<code>basename.properties</code>是缺省加载的资源文件，当客户端根据本地语言查找不到相关的资源文件时，则使用该配置文件。</p>
<p>创建文件<code>src/main/resources/messages.properties</code></p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">welcome.message</span> = <span class="string">北京欢迎你！</span></span><br></pre></td></tr></table></figure>
<p>创建文件<code>src/main/resources/messages_en_US.properties</code></p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">welcome.message</span> = <span class="string">Welcome to BeiJing!</span></span><br></pre></td></tr></table></figure>
<p>在 IntelliJ IDEA 编辑视图：</p>
<p><code>messages</code>是 Spring Boot 加载资源文件默认采用的名称（<code>basename</code>），如果你所使用的资源文件名称不是以<code>messages</code>命名或所使用的资源文件不是在<code>src/main/resources</code>根目录，你可以通过<code>spring.messages.basename</code>属性来做具体的配置。如，资源文件<code>messages.properties</code>和<code>messages_en_US.properties</code>假设它们所在的目录位置是<code>src/main/resources/i18n</code>。</p>
<p>application.properties 配置示例：</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">spring.messages.basename</span>:<span class="string">i18n/messages</span></span><br></pre></td></tr></table></figure>
<p>application.yml 配置示例：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring  messages    basename:</span> <span class="string">i18n/messages</span></span><br></pre></td></tr></table></figure>
<p>静态文本消息示例：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 北京欢迎你！ --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;#&#123;welcom.message&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>消息表达式<code>#&#123;&#125;</code>是不允许直接处理非静态的文本消息的，但是你可以在资源文件中通过使用占位符<code>&#123;&#125;</code>来处理非静态的文本消息：</p>
<p>messages.properties 配置示例：</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">welcome.user.message</span> = <span class="string">&#123;0&#125;, 北京欢迎你！</span></span><br></pre></td></tr></table></figure>
<p>messages_en_US.properties 配置示例：</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">welcome.user.message</span> = <span class="string">&#123;0&#125;, Welcome to BeiJing!</span></span><br></pre></td></tr></table></figure>
<p>非静态文本消息，以参数的形式传递变量的值：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- fanlychie, 北京欢迎你！ --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;#&#123;welcome.user.message($&#123;session.user.name&#125;)&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="2-1-4-…"><a href="#2-1-4-…" class="headerlink" title="2.1.4 @{…}"></a>2.1.4 @{…}</h4><p>链接表达式<code>@&#123;&#125;</code>是专门用来处理 URL 链接地址的。</p>
<p>绝对地址示例：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- https://fanlychie.github.io --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;@&#123;https://fanlychie.github.io&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>页面相对地址示例：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- commons/base.html --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;@&#123;commons/base.html&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>上下文相对地址（相对于当前的服务）示例：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- /css/mian.css --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;@&#123;/css/mian.css&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>服务器相对地址（相对于部署在同一个服务器中的不同服务）示例：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- /image/upload --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;@&#123;~/image/upload&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>参数使用示例：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- /css/mian.css?v=1.0 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;@&#123;/css/mian.css(v=1.0)&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- /user/order?username=fanlychie --&gt;</span><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;@&#123;/user/order(username=$&#123;session.user.name&#125;)&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- /user/order?username=fanlychie&amp;status=PAIED --&gt;</span><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;@&#123;/user/order(username=$&#123;session.user.name&#125;,status=&#x27;PAIED&#x27;)&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- /user/fanlychie/info --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;@&#123;/user/&#123;username&#125;/info(username=$&#123;session.user.name&#125;)&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="2-1-5-…"><a href="#2-1-5-…" class="headerlink" title="2.1.5 ~{…}"></a>2.1.5 ~{…}</h4><p>片段表达式<code>~&#123;&#125;</code>可以用来引用一段公共的 HTML 代码片段。</p>
<table>
<thead>
<tr>
<th align="center">语法</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="center">~{templatename}</td>
<td align="left">引用整个模板文件的代码片段</td>
</tr>
<tr>
<td align="center">~{templatename :: selector}</td>
<td align="left">selector 可以是 th:fragment 指定的名称或其他选择器。 如类选择器、ID选择器等</td>
</tr>
<tr>
<td align="center">~{::selector}</td>
<td align="left">相当于 ~{this :: selector}，表示引用当前模板定义的代码片段</td>
</tr>
</tbody></table>
<p>在 Thymeleaf 模板文件中，你可以使用<code>th:fragment</code>属性来定义一段公共的代码片段，然后你可以通过使用<code>th:insert</code>、<code>th:replace</code>、<code>th:include</code>（Thymeleaf 3.0 开始不再推荐使用，本文也将不再介绍它）属性来将这些公共的代码片段引入到模板文件中来。</p>
<p>src/main/resources/templates/base.html，通过<code>th:fragment</code>属性定义一段公共的代码片段：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;footer&quot;</span> <span class="attr">th:fragment</span>=<span class="string">&quot;footerFragment&quot;</span>&gt;</span><span class="symbol">&amp;copy;</span> 2017 fanlychie<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>src/main/resources/templates/index.html，通过<code>th:insert</code>属性引用一段公共的代码片段：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">th:insert</span>=<span class="string">&quot;~&#123;base :: footerFragment&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>其中，<code>~&#123;&#125;</code>是可选的，我们可以去掉这层的包裹：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">th:insert</span>=<span class="string">&quot;base :: footerFragment&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>若 index.html 与 base.html 不在同级目录，如 templates/commons/base.html：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">th:insert</span>=<span class="string">&quot;~&#123;commons/base :: footerFragment&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>使用<code>th:fragment</code>属性定义代码片段时，你还可以声明一组参数：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">th:fragment</span>=<span class="string">&quot;crumbs(parent, child)&quot;</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">i</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;parent&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">i</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">i</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;child&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">i</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span>    </span><br><span class="line"><span class="comment">&lt;!--&lt;i&gt;用户中心&lt;/i&gt;&lt;i&gt;我的订单&lt;/i&gt;--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">th:insert</span>=<span class="string">&quot;::crumbs(&#x27;用户中心&#x27;, &#x27;我的订单&#x27;)&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>此外，我们还可以通过类选择器、ID选择器等来引用公共的代码片段：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">th:insert</span>=<span class="string">&quot;~&#123;base :: #footer&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>除了<code>th:insert</code>属性<code>th:replace</code>也可以用来引用公共的代码片段。不同的是，<code>th:insert</code>是直接将代码片段插入到标签体内，而<code>th:replace</code>则是用代码片段直接替换标签体内容。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--&lt;div&gt;    &lt;div id=&quot;footer&quot;&gt;© 2017 fanlychie&lt;/div&gt;&lt;/div&gt;--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">th:insert</span>=<span class="string">&quot;~&#123;base :: footerFragment&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span>    </span><br><span class="line"><span class="comment">&lt;!--&lt;div id=&quot;footer&quot;&gt;© 2017 fanlychie&lt;/div&gt;--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">th:replace</span>=<span class="string">&quot;~&#123;base :: footerFragment&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="2-1-6-内置对象"><a href="#2-1-6-内置对象" class="headerlink" title="2.1.6 内置对象"></a>2.1.6 内置对象</h4><table>
<thead>
<tr>
<th align="left">对象</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3RoeW1lbGVhZi90aHltZWxlYWYvYmxvYi90aHltZWxlYWYtMy4wLjUuUkVMRUFTRS9zcmMvbWFpbi9qYXZhL29yZy90aHltZWxlYWYvY29udGV4dC9JQ29udGV4dC5qYXZh">#ctx<i class="fa fa-external-link-alt"></i></span></td>
<td align="left">上下文对象</td>
</tr>
<tr>
<td align="left"><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3RoeW1lbGVhZi90aHltZWxlYWYvYmxvYi90aHltZWxlYWYtMy4wLjUuUkVMRUFTRS9zcmMvbWFpbi9qYXZhL29yZy90aHltZWxlYWYvY29udGV4dC9JQ29udGV4dC5qYXZh">#vars<i class="fa fa-external-link-alt"></i></span></td>
<td align="left">同 #ctx，表示上下文变量</td>
</tr>
<tr>
<td align="left">#locale</td>
<td align="left">上下文本地化（特定的地理区域）变量，可参考 java.util.Locale</td>
</tr>
<tr>
<td align="left">#request</td>
<td align="left">HttpServletRequest 对象，可参考 javax.servlet.http.HttpServletRequest</td>
</tr>
<tr>
<td align="left">#response</td>
<td align="left">HttpServletResponse 对象，可参考 javax.servlet.http.HttpServletResponse</td>
</tr>
<tr>
<td align="left">#session</td>
<td align="left">HttpSession 对象，可参考 javax.servlet.http.HttpSession</td>
</tr>
<tr>
<td align="left">#servletContext</td>
<td align="left">ServletContext 对象，可参考 javax.servlet.ServletContext</td>
</tr>
</tbody></table>
<p><code>#ctx</code>示例：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- zh_CN --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#ctx.getLocale()&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- Welcome to BeiJing! --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#ctx.getVariable(&#x27;message&#x27;)&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- true --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#ctx.containsVariable(&#x27;message&#x27;)&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p><code>#vars</code>示例：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- zh_CN --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#vars.getLocale()&#125;&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">p</span>&gt;</span><span class="comment">&lt;!-- Welcome to BeiJing! --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#vars.getVariable(&#x27;message&#x27;)&#125;&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">p</span>&gt;</span><span class="comment">&lt;!-- true --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#vars.containsVariable(&#x27;message&#x27;)&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p><code>#locale</code>示例：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- zh_CN --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#locale&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- CN --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#locale.country&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 中国 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#locale.displayCountry&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- zh --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#locale.language&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 中文 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#locale.displayLanguage&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 中文 (中国) --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#locale.displayName&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p><code>#request</code>示例：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- HTTP/1.1 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#request.protocol&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- http --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#request.scheme&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- localhost --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#request.serverName&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 8080 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#request.serverPort&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- GET --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#request.method&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- /standard-expression-syntax/variables --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#request.requestURI&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- http://localhost:8080/standard-expression-syntax/variables --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#request.requestURL&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- /standard-expression-syntax/variables --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#request.servletPath&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- java.util.Collections$3@203646fe --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#request.parameterNames&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- &#123;q=[Ljava.lang.String;@3308c69f&#125; --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#request.parameterMap&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- q=expression --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#request.queryString&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>注意，请求地址的 URL 参数直接通过<code>#request.x</code>是取不出来的，需要使用<code>param.x</code>语法来取出。如，URL：<code>/standard-expression-syntax/variables?q=expression</code>，取出 q 参数的正确姿势：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;param.q&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p><code>#response</code>示例：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 200 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#response.status&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 8192 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#response.bufferSize&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- UTF-8 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#response.characterEncoding&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- text/html;charset=UTF-8 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#response.contentType&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p><code>#session</code>示例：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 2BCB2A0EACFF2D9D249D9799431B5127 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#session.id&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 1499786693244 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#session.lastAccessedTime&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- fanlychie --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#session.getAttribute(&#x27;user&#x27;).name&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>注意，放到会话里面的对象直接通过<code>#session.x</code>是取不出来的，需要使用<code>session.x</code>语法来取出。如，取出会话里面的 user 对象的正确姿势：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;session.user.name&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="2-1-7-工具类"><a href="#2-1-7-工具类" class="headerlink" title="2.1.7 工具类"></a>2.1.7 工具类</h4><table>
<thead>
<tr>
<th align="center">对象</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="center"><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3RoeW1lbGVhZi90aHltZWxlYWYvYmxvYi90aHltZWxlYWYtMy4wLjUuUkVMRUFTRS9zcmMvbWFpbi9qYXZhL29yZy90aHltZWxlYWYvZXhwcmVzc2lvbi9NZXNzYWdlcy5qYXZh">#messages<i class="fa fa-external-link-alt"></i></span></td>
<td align="center">消息工具类，与 ＃{…} 作用相同</td>
</tr>
<tr>
<td align="center"><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3RoeW1lbGVhZi90aHltZWxlYWYvYmxvYi90aHltZWxlYWYtMy4wLjUuUkVMRUFTRS9zcmMvbWFpbi9qYXZhL29yZy90aHltZWxlYWYvZXhwcmVzc2lvbi9VcmlzLmphdmE=">#uris<i class="fa fa-external-link-alt"></i></span></td>
<td align="center">地址相关的工具类</td>
</tr>
<tr>
<td align="center"><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3RoeW1lbGVhZi90aHltZWxlYWYvYmxvYi90aHltZWxlYWYtMy4wLjUuUkVMRUFTRS9zcmMvbWFpbi9qYXZhL29yZy90aHltZWxlYWYvZXhwcmVzc2lvbi9Db252ZXJzaW9ucy5qYXZh">#conversions<i class="fa fa-external-link-alt"></i></span></td>
<td align="center">对象转换工具类</td>
</tr>
<tr>
<td align="center"><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3RoeW1lbGVhZi90aHltZWxlYWYvYmxvYi90aHltZWxlYWYtMy4wLjUuUkVMRUFTRS9zcmMvbWFpbi9qYXZhL29yZy90aHltZWxlYWYvZXhwcmVzc2lvbi9EYXRlcy5qYXZh">#dates<i class="fa fa-external-link-alt"></i></span></td>
<td align="center">日期时间工具类</td>
</tr>
<tr>
<td align="center"><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3RoeW1lbGVhZi90aHltZWxlYWYvYmxvYi90aHltZWxlYWYtMy4wLjUuUkVMRUFTRS9zcmMvbWFpbi9qYXZhL29yZy90aHltZWxlYWYvZXhwcmVzc2lvbi9DYWxlbmRhcnMuamF2YQ==">#calendars<i class="fa fa-external-link-alt"></i></span></td>
<td align="center">日历工具类</td>
</tr>
<tr>
<td align="center"><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3RoeW1lbGVhZi90aHltZWxlYWYvYmxvYi90aHltZWxlYWYtMy4wLjUuUkVMRUFTRS9zcmMvbWFpbi9qYXZhL29yZy90aHltZWxlYWYvZXhwcmVzc2lvbi9OdW1iZXJzLmphdmE=">#numbers<i class="fa fa-external-link-alt"></i></span></td>
<td align="center">数字工具类</td>
</tr>
<tr>
<td align="center"><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3RoeW1lbGVhZi90aHltZWxlYWYvYmxvYi90aHltZWxlYWYtMy4wLjUuUkVMRUFTRS9zcmMvbWFpbi9qYXZhL29yZy90aHltZWxlYWYvZXhwcmVzc2lvbi9TdHJpbmdzLmphdmE=">#strings<i class="fa fa-external-link-alt"></i></span></td>
<td align="center">字符串工具类</td>
</tr>
<tr>
<td align="center"><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3RoeW1lbGVhZi90aHltZWxlYWYvYmxvYi90aHltZWxlYWYtMy4wLjUuUkVMRUFTRS9zcmMvbWFpbi9qYXZhL29yZy90aHltZWxlYWYvZXhwcmVzc2lvbi9PYmplY3RzLmphdmE=">#objects<i class="fa fa-external-link-alt"></i></span></td>
<td align="center">对象工具类</td>
</tr>
<tr>
<td align="center"><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3RoeW1lbGVhZi90aHltZWxlYWYvYmxvYi90aHltZWxlYWYtMy4wLjUuUkVMRUFTRS9zcmMvbWFpbi9qYXZhL29yZy90aHltZWxlYWYvZXhwcmVzc2lvbi9Cb29scy5qYXZh">#bools<i class="fa fa-external-link-alt"></i></span></td>
<td align="center">布尔工具类</td>
</tr>
<tr>
<td align="center"><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3RoeW1lbGVhZi90aHltZWxlYWYvYmxvYi90aHltZWxlYWYtMy4wLjUuUkVMRUFTRS9zcmMvbWFpbi9qYXZhL29yZy90aHltZWxlYWYvZXhwcmVzc2lvbi9BcnJheXMuamF2YQ==">#arrays<i class="fa fa-external-link-alt"></i></span></td>
<td align="center">数组工具类</td>
</tr>
<tr>
<td align="center"><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3RoeW1lbGVhZi90aHltZWxlYWYvYmxvYi90aHltZWxlYWYtMy4wLjUuUkVMRUFTRS9zcmMvbWFpbi9qYXZhL29yZy90aHltZWxlYWYvZXhwcmVzc2lvbi9MaXN0cy5qYXZh">#lists<i class="fa fa-external-link-alt"></i></span></td>
<td align="center">List 工具类</td>
</tr>
<tr>
<td align="center"><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3RoeW1lbGVhZi90aHltZWxlYWYvYmxvYi90aHltZWxlYWYtMy4wLjUuUkVMRUFTRS9zcmMvbWFpbi9qYXZhL29yZy90aHltZWxlYWYvZXhwcmVzc2lvbi9TZXRzLmphdmE=">#sets<i class="fa fa-external-link-alt"></i></span></td>
<td align="center">Set 工具类</td>
</tr>
<tr>
<td align="center"><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3RoeW1lbGVhZi90aHltZWxlYWYvYmxvYi90aHltZWxlYWYtMy4wLjUuUkVMRUFTRS9zcmMvbWFpbi9qYXZhL29yZy90aHltZWxlYWYvZXhwcmVzc2lvbi9NYXBzLmphdmE=">#maps<i class="fa fa-external-link-alt"></i></span></td>
<td align="center">Map 工具类</td>
</tr>
</tbody></table>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- false --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#strings.isEmpty(message)&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 2017-07-12 00:37:25 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;#dates.format(now, &#x27;yyyy-MM-dd HH:mm:ss&#x27;)&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="2-2-字面值"><a href="#2-2-字面值" class="headerlink" title="2.2 字面值"></a>2.2 字面值</h3><p>所谓字面值，首先它不是一个变量，它是一个具体的确切的值，通常这些值是比较简单的，例如：<code>18</code>、<code>&#39;welcome&#39;</code>等，它们没有名称，以至于我们只能用值来称呼它们，因此我们称其为字面值。</p>
<h4 id="2-2-1-文字字面值"><a href="#2-2-1-文字字面值" class="headerlink" title="2.2.1 文字字面值"></a>2.2.1 文字字面值</h4><p>文字字面值是用单引号引起来的任何字符内容，如果字符内容里面含有单引号，则需要进行转义：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- Welcome to BeiJing! --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;&#x27;Welcome to BeiJing!&#x27;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- &#x27;Welcome to BeiJing!&#x27; --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;&#x27;\&#x27;Welcome to BeiJing!\&#x27;&#x27;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="2-2-2-数字字面值"><a href="#2-2-2-数字字面值" class="headerlink" title="2.2.2 数字字面值"></a>2.2.2 数字字面值</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 2017 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;2017&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 2018 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;2017 + 1&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="2-2-3-布尔字面值"><a href="#2-2-3-布尔字面值" class="headerlink" title="2.2.3 布尔字面值"></a>2.2.3 布尔字面值</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- false --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;1 &gt; 2&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">p</span>&gt;</span><span class="comment">&lt;!-- 否 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;1 &gt; 2 ? &#x27;是&#x27; : &#x27;否&#x27;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="2-2-4-空字面值"><a href="#2-2-4-空字面值" class="headerlink" title="2.2.4 空字面值"></a>2.2.4 空字面值</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- false --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;user == null&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="2-2-5-字面令牌"><a href="#2-2-5-字面令牌" class="headerlink" title="2.2.5 字面令牌"></a>2.2.5 字面令牌</h4><p>字面令牌（Literal Tokens）的内容只能含有（不能含有空格、特殊符号等）：</p>
<ul>
<li>大写或小写的字母、中文等不含空格和特殊符号的文本</li>
<li>0 到 9 的数字</li>
<li>中括号</li>
<li>下划线</li>
<li>连字符（-）</li>
<li>点符号（.）</li>
</ul>
<p>实际上，数字、布尔和空字面值都是字面令牌的特殊情况。字面令牌能够用来对标准表达式语法进行简化，我们可以将包裹它的内容的单引号去掉：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;Welcome to BeiJing!&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>它等效于：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;&#x27;Welcome to BeiJing!&#x27;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="2-3-文本操作"><a href="#2-3-文本操作" class="headerlink" title="2.3 文本操作"></a>2.3 文本操作</h3><p>我们可以对文本内容进行两种常用的操作，它们分别为字符串连接和字符串替换。</p>
<h4 id="2-3-1-字符串连接"><a href="#2-3-1-字符串连接" class="headerlink" title="2.3.1 字符串连接"></a>2.3.1 字符串连接</h4><p>不管是字面值还是表达式的结果，我们都可以使用<code>+</code>符号将它们连接起来：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- Welcome to BeiJing! --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;&#x27;Welcome to &#x27; + $&#123;location&#125; + &#x27;!&#x27;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="2-3-2-字面值替换"><a href="#2-3-2-字面值替换" class="headerlink" title="2.3.2 字面值替换"></a>2.3.2 字面值替换</h4><p>符号<code>||</code>可以用来将字面值和表达式包裹起来，这样就能方便的替换变量的值，而不需要使用<code>+</code>连接符：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- Welcome to BeiJing! --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;|Welcome to $&#123;location&#125;!|&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="2-4-算术运算"><a href="#2-4-算术运算" class="headerlink" title="2.4 算术运算"></a>2.4 算术运算</h3><p>支持<code>+</code>（加）、<code>-</code>（减）、<code>*</code>（乘）、<code>/</code>（除）、<code>%</code>（模）运算：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 6 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;4 + 2&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 2 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;4 - 2&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 8 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;4 * 2&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 2 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;4 / 2&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 0 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;4 % 2&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 2 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;pagination.page + 1&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- 2 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;pagination.page&#125; + 1&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="2-5-布尔运算"><a href="#2-5-布尔运算" class="headerlink" title="2.5 布尔运算"></a>2.5 布尔运算</h3><p>支持<code>and</code>（且）、<code>or</code>（或）、<code>!</code>（非）、<code>not</code>（非）运算：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;user.online and user.vip&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;user.online or user.vip&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;!user.online&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;not user.online&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="2-6-比较和相等"><a href="#2-6-比较和相等" class="headerlink" title="2.6 比较和相等"></a>2.6 比较和相等</h3><p>支持<code>&lt;</code>（<code>lt</code>）、<code>&gt;</code>（<code>gt</code>）、<code>&lt;=</code>（<code>le</code>）、<code>&gt;=</code>（<code>ge</code>）、<code>==</code>（<code>eq</code>）、<code>！=</code>（<code>ne</code>）：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;user.age &lt; 60&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;user.age &lt;= 60&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;user.age &gt; 18&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;user.age &gt;= 18&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;user.age == 18&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;user.age != 18&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="2-7-条件运算"><a href="#2-7-条件运算" class="headerlink" title="2.7 条件运算"></a>2.7 条件运算</h3><p>三元运算符：<code>(if) ? (then) : (else)</code></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;user.online ? &#x27;在线&#x27; : &#x27;离线&#x27;&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;user.online ? (user.vip ? &#x27;VIP用户在线&#x27; : &#x27;普通用户在线&#x27;) : &#x27;离线&#x27;&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>二元运算符：<code>(value) ?: (defaultValue)</code>。</p>
<p>其中，<code>value</code>非空（null）即真，条件为真时输出<code>value</code>，否则输出<code>defaultValue</code>。假设<code>token = null</code>，<code>user.email = fanlychie@gmail.com</code></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 你还没有登录，请先登录 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;token&#125; ?: &#x27;你还没有登录，请先登录&#x27;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- fanlychie@gmail.com --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;user.email&#125; ?: &#x27;你还没有绑定邮箱&#x27;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="2-8-无操作符"><a href="#2-8-无操作符" class="headerlink" title="2.8 无操作符"></a>2.8 无操作符</h3><p>当模板运行在服务器端时，Thymeleaf 会解析<code>th:*</code>属性的具体值替换标签体的内容。无操作符（<code>_</code>）则允许你使用原型标签体的内容作为默认值：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 你还没有登录，请先登录 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;token&#125; ?: _&quot;</span>&gt;</span>你还没有登录，请先登录<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h2 id="3-使用文本"><a href="#3-使用文本" class="headerlink" title="3. 使用文本"></a>3. 使用文本</h2><p>首先介绍两个最基础的<code>th:*</code>属<code>th:text</code>和<code>th:utext</code>，它们都是用于处理文本消息内容。</p>
<h3 id="3-1-th-text"><a href="#3-1-th-text" class="headerlink" title="3.1 th:text"></a>3.1 th:text</h3><p>在标签体中展示表达式评估结果的文本内容：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;message&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>使用外部化的文本内容：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;message&#125;&quot;</span>&gt;</span>Welcome to BeiJing!<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>当它作为静态文件直接运行时，浏览器会自动忽略它不能识别的<code>th:text</code>属性，而显示<code>&lt;p&gt;</code>标签体的文本内容<code>Welcome to BeiJing!</code></p>
<p>当它作为模板文件运行在服务器端时，<code>th:text</code>属性的具体值将会替换<code>&lt;p&gt;</code>标签体的文本内容。</p>
<h3 id="3-2-th-utext"><a href="#3-2-th-utext" class="headerlink" title="3.2 th:utext"></a>3.2 th:utext</h3><p>属性<code>th:utext</code>与<code>th:text</code>的区别在于：</p>
<ul>
<li><code>th:text</code>默认会对含有 HTML 标签的内容进行字符转义；</li>
<li><code>th:utext</code>（Unescaped Text）则不会对含有 HTML 标签的内容进行字符转义；</li>
</ul>
<p>假设：<code>message = &quot;&lt;b&gt;Welcome to BeiJing!&lt;/b&gt;&quot;</code>。</p>
<p>使用<code>th:text</code>属性：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;message&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p><code>th:text</code>效果：<b>Welcome to BeiJing!</b></p>
<p>使用<code>th:utext</code>属性：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:utext</span>=<span class="string">&quot;$&#123;message&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p><code>th:utext</code>效果：<b>Welcome to BeiJing!</b></p>
<h2 id="4-设置属性值"><a href="#4-设置属性值" class="headerlink" title="4. 设置属性值"></a>4. 设置属性值</h2><p>在 Thymeleaf 模板文件中，你可以使用<code>th:*</code>（或者使用<code>th:attr</code>属性）来设置任意的 HTML5 标签属性的值。不仅如此，你还可以<code>th:*-*</code>来同时为多个不同的标签属性设置相同的一个值，甚至你可以使用<code>th:attrappend</code>和<code>th:attrprepend</code>来追加新的值到现有的标签属性值中。</p>
<h3 id="4-1-th-attr"><a href="#4-1-th-attr" class="headerlink" title="4.1 th:attr"></a>4.1 th:attr</h3><p>这种方式是不被推荐的，了解一下就行。下面是用<code>th:attr=&quot;href=...&quot;</code>来设置标签<code>href</code>属性的值：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">th:attr</span>=<span class="string">&quot;href=@&#123;https://www.google.com.hk&#125;&quot;</span>&gt;</span>谷歌一下你就知道<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="4-2-th"><a href="#4-2-th" class="headerlink" title="4.2 th:*"></a>4.2 th:*</h3><p>显然<code>th:attr=&quot;href=@&#123;http://www.baidu.com&#125;&quot;</code>不够简洁，我们更推荐下面的这种语法：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">th:href</span>=<span class="string">&quot;@&#123;https://www.google.com.hk&#125;&quot;</span>&gt;</span>谷歌一下你就知道<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>其中<code>th:*</code>中的<code>*</code>可以是 HTML5 支持的任意属性名称，甚至这些属性名称可以是自定义的：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- &lt;div item-id=&quot;1001&quot;&gt;Welcome to BeiJing!&lt;/div&gt; --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">th:item-id</span>=<span class="string">&quot;$&#123;user.id&#125;&quot;</span>&gt;</span>Welcome to BeiJing!<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="4-3-th"><a href="#4-3-th" class="headerlink" title="4.3 th:-"></a>4.3 th:<em>-</em></h3><p>如果想要同时为标签的多个不同属性设置相同的一个值，可以使用<code>th:*-*</code>的语法：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">img</span> <span class="attr">src</span>=<span class="string">&quot;logo.png&quot;</span> <span class="attr">th:alt-title</span>=<span class="string">&quot;LOGO图片&quot;</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>它相当于：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">img</span> <span class="attr">src</span>=<span class="string">&quot;logo.png&quot;</span> <span class="attr">th:alt</span>=<span class="string">&quot;LOGO图片&quot;</span> <span class="attr">th:title</span>=<span class="string">&quot;LOGO图片&quot;</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="4-4-th-attrappend-amp-th-attrprepend"><a href="#4-4-th-attrappend-amp-th-attrprepend" class="headerlink" title="4.4 th:attrappend &amp; th:attrprepend"></a>4.4 th:attrappend &amp; th:attrprepend</h3><p><code>th:attrappend</code>和<code>th:attrprepend</code>可以将表达式的结果分别追加到指定的属性值之后和之前。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- &lt;button class=&quot;btn enable&quot;&gt;购买&lt;/button&gt; --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">button</span> <span class="attr">class</span>=<span class="string">&quot;btn&quot;</span> <span class="attr">th:attrappend</span>=<span class="string">&quot;class=$&#123;outOfStock&#125; ? &#x27; enable&#x27; : &#x27; disable&#x27;&quot;</span>&gt;</span>购买<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- &lt;button class=&quot;enable btn&quot;&gt;购买&lt;/button&gt; --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">button</span> <span class="attr">class</span>=<span class="string">&quot;btn&quot;</span> <span class="attr">th:attrprepend</span>=<span class="string">&quot;class=$&#123;outOfStock&#125; ? &#x27;enable &#x27; : &#x27;disable &#x27;&quot;</span>&gt;</span>购买<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>另外，还有两个常用的具体附加属性<code>th:classappend=&quot;...&quot;</code>和<code>th:styleappend=&quot;&quot;</code>。</p>
<p>它们分别用来代替<code>th:attrappend=&quot;class=...&quot;</code>和<code>th:attrappend=&quot;style=...&quot;</code>。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- &lt;button class=&quot;btn enable&quot;&gt;购买&lt;/button&gt; --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">button</span> <span class="attr">class</span>=<span class="string">&quot;btn&quot;</span> <span class="attr">th:classappend</span>=<span class="string">&quot;$&#123;outOfStock&#125; ? &#x27; enable&#x27; : &#x27; disable&#x27;&quot;</span>&gt;</span>购买<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="4-5-布尔属性"><a href="#4-5-布尔属性" class="headerlink" title="4.5 布尔属性"></a>4.5 布尔属性</h3><p>在 HTML 中有些属性是布尔属性，布尔属性是指没有值的属性，如<code>readonly</code>、<code>checked</code>、<code>selected</code>等。它们若存在那就意味着值为 true。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;checkbox&quot;</span> <span class="attr">name</span>=<span class="string">&quot;rememberme&quot;</span> <span class="attr">checked</span> /&gt;</span> 记住我</span><br><span class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;radio&quot;</span> <span class="attr">name</span>=<span class="string">&quot;sex&quot;</span> <span class="attr">value</span>=<span class="string">&quot;male&quot;</span> <span class="attr">checked</span>&gt;</span> 男</span><br><span class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;radio&quot;</span> <span class="attr">name</span>=<span class="string">&quot;sex&quot;</span> <span class="attr">value</span>=<span class="string">&quot;female&quot;</span>&gt;</span> 女</span><br><span class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">name</span>=<span class="string">&quot;appId&quot;</span> <span class="attr">value</span>=<span class="string">&quot;J123654&quot;</span> <span class="attr">readonly</span>&gt;</span><span class="tag">&lt;<span class="name">select</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">option</span> <span class="attr">selected</span>&gt;</span>北京<span class="tag">&lt;/<span class="name">option</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">option</span>&gt;</span>上海<span class="tag">&lt;/<span class="name">option</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">option</span>&gt;</span>广州<span class="tag">&lt;/<span class="name">option</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">option</span>&gt;</span>深圳<span class="tag">&lt;/<span class="name">option</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>Thymeleaf 也允许我们通过<code>th:*</code>（这里的<code>*</code>表示任意的布尔属性） 来选择是否使用这些布尔属性。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;checkbox&quot;</span> <span class="attr">name</span>=<span class="string">&quot;rememberme&quot;</span> <span class="attr">ch:checked</span>=<span class="string">&quot;$&#123;rememberme&#125;&quot;</span> /&gt;</span> 记住我</span><br></pre></td></tr></table></figure>
<p>正如你所见，如果表达式的结果为<code>true</code>，则自动勾选复选框，若为<code>false</code>，则不会自动勾选。</p>
<h2 id="5-遍历"><a href="#5-遍历" class="headerlink" title="5. 遍历"></a>5. 遍历</h2><p>遍历（迭代）的语法<code>th:each=&quot;自定义的元素变量名称 : $&#123;集合变量名称&#125;&quot;</code>：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">spn</span>&gt;</span>你所在城市：<span class="tag">&lt;/<span class="name">spn</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">name</span>=<span class="string">&quot;mycity&quot;</span>&gt;</span>       </span><br><span class="line">        <span class="tag">&lt;<span class="name">option</span> <span class="attr">th:each</span>=<span class="string">&quot;city : $&#123;cities&#125;&quot;</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;city.name&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">option</span>&gt;</span>   </span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>属性<code>th:each</code>提供了一个用于跟踪迭代的状态变量，它包含以下几个属性：</p>
<table>
<thead>
<tr>
<th align="center">属性</th>
<th align="center">类型</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="center">index</td>
<td align="center">int</td>
<td align="center">当前迭代的索引，从 0 开始</td>
</tr>
<tr>
<td align="center">count</td>
<td align="center">int</td>
<td align="center">当前迭代的计数，从 1 开始</td>
</tr>
<tr>
<td align="center">size</td>
<td align="center">int</td>
<td align="center">集合中元素的总个数</td>
</tr>
<tr>
<td align="center">current</td>
<td align="center">int</td>
<td align="center">当前的元素对象</td>
</tr>
<tr>
<td align="center">even</td>
<td align="center">boolean</td>
<td align="center">当前迭代的计数是否是偶数</td>
</tr>
<tr>
<td align="center">odd</td>
<td align="center">boolean</td>
<td align="center">当前迭代的计数是否是奇数</td>
</tr>
<tr>
<td align="center">first</td>
<td align="center">boolean</td>
<td align="center">当前元素是否是集合的第一个元素</td>
</tr>
<tr>
<td align="center">last</td>
<td align="center">boolean</td>
<td align="center">当前元素是否是集合的最后一个元素</td>
</tr>
</tbody></table>
<p>状态变量的使用语法：<code>th:each=&quot;自定义的元素变量名称, 自定义的状态变量名称 : $&#123;集合变量名称&#125;&quot;</code>：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">spn</span>&gt;</span>所在城市：<span class="tag">&lt;/<span class="name">spn</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">name</span>=<span class="string">&quot;mycity&quot;</span>&gt;</span>        </span><br><span class="line">        <span class="tag">&lt;<span class="name">option</span> <span class="attr">th:each</span>=<span class="string">&quot;city, status : $&#123;cities&#125;&quot;</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;city.name&#125;&quot;</span> <span class="attr">th:item-index</span>=<span class="string">&quot;$&#123;status.count&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">option</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>不管什么时候，Thymeleaf 始终会为每个<code>th:each</code>创建一个状态变量，默认的状态变量名称就是自定义的元素变量名称后面加<code>Stat</code>字符串组成：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">spn</span>&gt;</span>所在城市：<span class="tag">&lt;/<span class="name">spn</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">name</span>=<span class="string">&quot;mycity&quot;</span>&gt;</span>        </span><br><span class="line">        <span class="tag">&lt;<span class="name">option</span> <span class="attr">th:each</span>=<span class="string">&quot;city : $&#123;cities&#125;&quot;</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;city.name&#125;&quot;</span> <span class="attr">th:item-index</span>=<span class="string">&quot;$&#123;cityStat.count&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">option</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h2 id="6-条件判断"><a href="#6-条件判断" class="headerlink" title="6. 条件判断"></a>6. 条件判断</h2><p>条件判断语句有三种，分别是：<code>th:if</code>、<code>th:unless</code>、<code>th:swith</code>。</p>
<h3 id="6-1-th-if"><a href="#6-1-th-if" class="headerlink" title="6.1 th:if"></a>6.1 th:if</h3><p>当表达式的评估结果为真时则显示内容，否则不显示：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">th:href</span>=<span class="string">&quot;@&#123;/user/order(uid=$&#123;user.id&#125;)&#125;&quot;</span> <span class="attr">th:if</span>=<span class="string">&quot;$&#123;user != null&#125;&quot;</span>&gt;</span>我的订单<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>真假评估的依据：</p>
<ul>
<li>当表达式的值不为空（null）时<ul>
<li>如果表达式的值是一个布尔类型，且值为<code>true</code>评估为真，否则为假</li>
<li>如果表达式的值是一个数字 类型，且值为非<code>0</code>评估为真，否则为假</li>
<li>如果表达式的值是一个字符类型，且值为非<code>0</code>评估为真，否则为假</li>
<li>如果表达式的值是一个字符串类型，且值为非<code>&quot;false&quot;</code>、<code>&quot;off&quot;</code>、<code>&quot;no&quot;</code>评估为真，否则为假</li>
<li>如果表达式的值不是一个<code>布尔</code>、<code>数字</code>、<code>字符</code>或<code>字符串</code>评估为真</li>
</ul>
</li>
<li>当表达式的值为空（null）时，评估结果为假</li>
</ul>
<p>因此，上面代码我们也可以简写成：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">th:href</span>=<span class="string">&quot;@&#123;/user/order(uid=$&#123;user.id&#125;)&#125;&quot;</span> <span class="attr">th:if</span>=<span class="string">&quot;$&#123;user&#125;&quot;</span>&gt;</span>我的订单<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>但是，为了代码的可读性，我们并不建议这样使用。</p>
<h3 id="6-2-th-unless"><a href="#6-2-th-unless" class="headerlink" title="6.2 th:unless"></a>6.2 th:unless</h3><p><code>th:unless</code>与<code>th:if</code>判断恰好相反，当表达式的评估结果为假时则显示内容，否则不显示：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">th:href</span>=<span class="string">&quot;@&#123;/user/order(uid=$&#123;user.id&#125;)&#125;&quot;</span> <span class="attr">th:unless</span>=<span class="string">&quot;$&#123;user == null&#125;&quot;</span>&gt;</span>我的订单<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="6-3-th-swith"><a href="#6-3-th-swith" class="headerlink" title="6.3 th:swith"></a>6.3 th:swith</h3><p>多路选择语句，它需要搭配<code>th:case</code>来使用：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">th:switch</span>=<span class="string">&quot;$&#123;user.role&#125;&quot;</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span> <span class="attr">th:case</span>=<span class="string">&quot;admin&quot;</span>&gt;</span>管理员<span class="tag">&lt;/<span class="name">p</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span> <span class="attr">th:case</span>=<span class="string">&quot;user&quot;</span>&gt;</span>普通用户<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h2 id="7-定义局部变量"><a href="#7-定义局部变量" class="headerlink" title="7. 定义局部变量"></a>7. 定义局部变量</h2><p>使用<code>th:with</code>属性可以定义局部变量：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:with</span>=<span class="string">&quot;name=&#x27;fanlychie&#x27;&quot;</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">span</span> <span class="attr">th:text</span>=<span class="string">&quot;$&#123;name&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>同时定义多个局部变量时，用英文<code>,</code>号分隔开：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:with</span>=<span class="string">&quot;name=$&#123;user.name&#125;,age=&#123;user.age&#125;&quot;</span>&gt;</span>    ......<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h2 id="8-注释"><a href="#8-注释" class="headerlink" title="8. 注释"></a>8. 注释</h2><p>下面介绍常见的两种注释：</p>
<h3 id="8-1-标准注释"><a href="#8-1-标准注释" class="headerlink" title="8.1 标准注释"></a>8.1 标准注释</h3><p>语法：<code>&lt;!-- ... ---&gt;</code>，注释的代码块会在文件源代码中显示出来。</p>
<h4 id="8-1-1-单行注释"><a href="#8-1-1-单行注释" class="headerlink" title="8.1.1 单行注释"></a>8.1.1 单行注释</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- &lt;span&gt;$&#123;message&#125;&lt;/span&gt; ---&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="8-1-2-多行注释"><a href="#8-1-2-多行注释" class="headerlink" title="8.1.2 多行注释"></a>8.1.2 多行注释</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--</span></span><br><span class="line"><span class="comment">	&lt;div th:switch=&quot;$&#123;user.role&#125;&quot;&gt;    </span></span><br><span class="line"><span class="comment">		&lt;p th:case=&quot;admin&quot;&gt;管理员&lt;/p&gt;    </span></span><br><span class="line"><span class="comment">		&lt;p th:case=&quot;user&quot;&gt;普通用户&lt;/p&gt;</span></span><br><span class="line"><span class="comment">	&lt;/div&gt;</span></span><br><span class="line"><span class="comment">---&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="8-2-解析器级注释"><a href="#8-2-解析器级注释" class="headerlink" title="8.2 解析器级注释"></a>8.2 解析器级注释</h3><p>语法：<code>&lt;!--/* ... */--&gt;</code>，注释的代码块会在引擎解析的时候抹去。</p>
<h4 id="8-2-1-单行注释："><a href="#8-2-1-单行注释：" class="headerlink" title="8.2.1 单行注释："></a>8.2.1 单行注释：</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--/* &lt;span&gt;$&#123;message&#125;&lt;/span&gt; */--&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="8-2-2-多行注释"><a href="#8-2-2-多行注释" class="headerlink" title="8.2.2 多行注释"></a>8.2.2 多行注释</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--/*--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">th:switch</span>=<span class="string">&quot;$&#123;user.role&#125;&quot;</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span> <span class="attr">th:case</span>=<span class="string">&quot;admin&quot;</span>&gt;</span>管理员<span class="tag">&lt;/<span class="name">p</span>&gt;</span>    </span><br><span class="line">    <span class="tag">&lt;<span class="name">p</span> <span class="attr">th:case</span>=<span class="string">&quot;user&quot;</span>&gt;</span>普通用户<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!--*/--&gt;</span></span><br></pre></td></tr></table></figure>
<h2 id="9-内联表达式"><a href="#9-内联表达式" class="headerlink" title="9. 内联表达式"></a>9. 内联表达式</h2><p>内联表达式允许我们直接在 HTML 文本中使用标准表达式，而不需要使用<code>th:*</code>标签属性。</p>
<h3 id="9-1-…"><a href="#9-1-…" class="headerlink" title="9.1 [[…]]"></a>9.1 [[…]]</h3><p><code>[[]]</code>相当于<code>th:text</code>，对含有 HTML 标签的内容自动进行字符转义。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span>&gt;</span>The message is : [[$&#123;htmlContent&#125;]]<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="9-2-…"><a href="#9-2-…" class="headerlink" title="9.2 [(…)]"></a>9.2 [(…)]</h3><p><code>[()]</code>相当于<code>th:utext</code>，对含有 HTML 标签的内容不进行字符转义。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">p</span>&gt;</span>The message is : [($&#123;htmlContent&#125;)]<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="9-3-th-inline"><a href="#9-3-th-inline" class="headerlink" title="9.3 th:inline"></a>9.3 th:inline</h3><p>我们已经了解到，使用<code>[[]]</code>和<code>[()]</code>语法可以直接在 HTML 文本中使用标准表达式，如果想要使用更多高级的功能，需要使用<code>th:inline</code>属性来激活，它的取值如下：</p>
<table>
<thead>
<tr>
<th align="center">值</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="center">none</td>
<td align="center">禁止内联表达式，可以原样输出 [[]] 和 [()] 字符串</td>
</tr>
<tr>
<td align="center">text</td>
<td align="center">文本内联，可以使用 th:each 等高级语法</td>
</tr>
<tr>
<td align="center">css</td>
<td align="center">样式内联，如：<code>&lt;style th:inline=&quot;css&quot;&gt;</code></td>
</tr>
<tr>
<td align="center">javascript</td>
<td align="center">脚本内联，如：<code>&lt;style th:inline=&quot;javascript&quot;&gt;</code></td>
</tr>
</tbody></table>
<h4 id="9-3-1-none"><a href="#9-3-1-none" class="headerlink" title="9.3.1 none"></a>9.3.1 none</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- [[1, 2], [3, 4]] --&gt;</span><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:inline</span>=<span class="string">&quot;none&quot;</span>&gt;</span>[[1, 2], [3, 4]]<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="9-3-2-text"><a href="#9-3-2-text" class="headerlink" title="9.3.2 text"></a>9.3.2 text</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 北京 上海 广州 深圳 --&gt;</span><span class="tag">&lt;<span class="name">p</span> <span class="attr">th:inline</span>=<span class="string">&quot;text&quot;</span>&gt;</span>    [# th:each=&quot;city : $&#123;cities&#125;&quot;]        [($&#123;city.name&#125;)]    [/]<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="9-3-3-css"><a href="#9-3-3-css" class="headerlink" title="9.3.3 css"></a>9.3.3 css</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">style</span> <span class="attr">th:inline</span>=<span class="string">&quot;css&quot;</span>&gt;</span>    </span><br><span class="line"><span class="css">    <span class="selector-tag">body</span> &#123;        </span></span><br><span class="line"><span class="css">        <span class="attribute">background-color</span>:[[$&#123;bgColor&#125;]];    </span></span><br><span class="line">    &#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="9-3-4-javascript"><a href="#9-3-4-javascript" class="headerlink" title="9.3.4 javascript"></a>9.3.4 javascript</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">th:inline</span>=<span class="string">&quot;javascript&quot;</span>&gt;</span><span class="javascript">    <span class="keyword">var</span> user = [[$&#123;user&#125;]];    alert(<span class="string">&quot;用户名：&quot;</span> + user.name);</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>参考文档文献链接：<span class="exturl" data-url="aHR0cDovL3d3dy50aHltZWxlYWYub3JnL2RvYy90dXRvcmlhbHMvMy4wL3VzaW5ndGh5bWVsZWFmLmh0bWw=">http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html<i class="fa fa-external-link-alt"></i></span></p>
</blockquote>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/java/" rel="tag"># java</a>
              <a href="/tags/spring/" rel="tag"># spring</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/01/03/%E5%B0%8F%E7%94%9F%E5%8D%9A%E5%AE%A2/java/Spring%20Boot%E7%AC%94%E8%AE%B0/" rel="prev" title="springboot入门">
      <i class="fa fa-chevron-left"></i> springboot入门
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/01/03/%E5%B0%8F%E7%94%9F%E5%8D%9A%E5%AE%A2/linux/03_SHELL%E7%BC%96%E7%A8%8B%E4%B9%8B%E6%9D%A1%E4%BB%B6%E5%88%A4%E6%96%AD%E5%92%8C%E6%B5%81%E7%A8%8B%E6%8E%A7%E5%88%B6/" rel="next" title="03_SHELL编程之条件判断和流程控制">
      03_SHELL编程之条件判断和流程控制 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E6%A0%87%E5%87%86%E8%A1%A8%E8%BE%BE%E5%BC%8F%E8%AF%AD%E6%B3%95"><span class="nav-number">1.</span> <span class="nav-text">1. 标准表达式语法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-%E7%AE%80%E4%BB%8B"><span class="nav-number">1.1.</span> <span class="nav-text">1.1 简介</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-%E5%BC%95%E5%85%A5"><span class="nav-number">1.2.</span> <span class="nav-text">1.2 引入</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%A0%87%E5%87%86%E8%A1%A8%E8%BE%BE%E5%BC%8F%E8%AF%AD%E6%B3%95"><span class="nav-number">2.</span> <span class="nav-text">2. 标准表达式语法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E7%AE%80%E5%8D%95%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="nav-number">2.1.</span> <span class="nav-text">2.1 简单表达式</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-1-%E2%80%A6"><span class="nav-number">2.1.1.</span> <span class="nav-text">2.1.1 ${…}</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-2-%E2%80%A6"><span class="nav-number">2.1.2.</span> <span class="nav-text">2.1.2 *{…}</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-3-%E2%80%A6"><span class="nav-number">2.1.3.</span> <span class="nav-text">2.1.3 #{…}</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-4-%E2%80%A6"><span class="nav-number">2.1.4.</span> <span class="nav-text">2.1.4 @{…}</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-5-%E2%80%A6"><span class="nav-number">2.1.5.</span> <span class="nav-text">2.1.5 ~{…}</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-6-%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1"><span class="nav-number">2.1.6.</span> <span class="nav-text">2.1.6 内置对象</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-7-%E5%B7%A5%E5%85%B7%E7%B1%BB"><span class="nav-number">2.1.7.</span> <span class="nav-text">2.1.7 工具类</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E5%AD%97%E9%9D%A2%E5%80%BC"><span class="nav-number">2.2.</span> <span class="nav-text">2.2 字面值</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-1-%E6%96%87%E5%AD%97%E5%AD%97%E9%9D%A2%E5%80%BC"><span class="nav-number">2.2.1.</span> <span class="nav-text">2.2.1 文字字面值</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-2-%E6%95%B0%E5%AD%97%E5%AD%97%E9%9D%A2%E5%80%BC"><span class="nav-number">2.2.2.</span> <span class="nav-text">2.2.2 数字字面值</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-3-%E5%B8%83%E5%B0%94%E5%AD%97%E9%9D%A2%E5%80%BC"><span class="nav-number">2.2.3.</span> <span class="nav-text">2.2.3 布尔字面值</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-4-%E7%A9%BA%E5%AD%97%E9%9D%A2%E5%80%BC"><span class="nav-number">2.2.4.</span> <span class="nav-text">2.2.4 空字面值</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-5-%E5%AD%97%E9%9D%A2%E4%BB%A4%E7%89%8C"><span class="nav-number">2.2.5.</span> <span class="nav-text">2.2.5 字面令牌</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-%E6%96%87%E6%9C%AC%E6%93%8D%E4%BD%9C"><span class="nav-number">2.3.</span> <span class="nav-text">2.3 文本操作</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-1-%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%BF%9E%E6%8E%A5"><span class="nav-number">2.3.1.</span> <span class="nav-text">2.3.1 字符串连接</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-2-%E5%AD%97%E9%9D%A2%E5%80%BC%E6%9B%BF%E6%8D%A2"><span class="nav-number">2.3.2.</span> <span class="nav-text">2.3.2 字面值替换</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-%E7%AE%97%E6%9C%AF%E8%BF%90%E7%AE%97"><span class="nav-number">2.4.</span> <span class="nav-text">2.4 算术运算</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-5-%E5%B8%83%E5%B0%94%E8%BF%90%E7%AE%97"><span class="nav-number">2.5.</span> <span class="nav-text">2.5 布尔运算</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-6-%E6%AF%94%E8%BE%83%E5%92%8C%E7%9B%B8%E7%AD%89"><span class="nav-number">2.6.</span> <span class="nav-text">2.6 比较和相等</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-7-%E6%9D%A1%E4%BB%B6%E8%BF%90%E7%AE%97"><span class="nav-number">2.7.</span> <span class="nav-text">2.7 条件运算</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-8-%E6%97%A0%E6%93%8D%E4%BD%9C%E7%AC%A6"><span class="nav-number">2.8.</span> <span class="nav-text">2.8 无操作符</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E4%BD%BF%E7%94%A8%E6%96%87%E6%9C%AC"><span class="nav-number">3.</span> <span class="nav-text">3. 使用文本</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-th-text"><span class="nav-number">3.1.</span> <span class="nav-text">3.1 th:text</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-th-utext"><span class="nav-number">3.2.</span> <span class="nav-text">3.2 th:utext</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E8%AE%BE%E7%BD%AE%E5%B1%9E%E6%80%A7%E5%80%BC"><span class="nav-number">4.</span> <span class="nav-text">4. 设置属性值</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-th-attr"><span class="nav-number">4.1.</span> <span class="nav-text">4.1 th:attr</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-th"><span class="nav-number">4.2.</span> <span class="nav-text">4.2 th:*</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-3-th"><span class="nav-number">4.3.</span> <span class="nav-text">4.3 th:-</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-4-th-attrappend-amp-th-attrprepend"><span class="nav-number">4.4.</span> <span class="nav-text">4.4 th:attrappend &amp; th:attrprepend</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-5-%E5%B8%83%E5%B0%94%E5%B1%9E%E6%80%A7"><span class="nav-number">4.5.</span> <span class="nav-text">4.5 布尔属性</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E9%81%8D%E5%8E%86"><span class="nav-number">5.</span> <span class="nav-text">5. 遍历</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-%E6%9D%A1%E4%BB%B6%E5%88%A4%E6%96%AD"><span class="nav-number">6.</span> <span class="nav-text">6. 条件判断</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#6-1-th-if"><span class="nav-number">6.1.</span> <span class="nav-text">6.1 th:if</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-2-th-unless"><span class="nav-number">6.2.</span> <span class="nav-text">6.2 th:unless</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-3-th-swith"><span class="nav-number">6.3.</span> <span class="nav-text">6.3 th:swith</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-%E5%AE%9A%E4%B9%89%E5%B1%80%E9%83%A8%E5%8F%98%E9%87%8F"><span class="nav-number">7.</span> <span class="nav-text">7. 定义局部变量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-%E6%B3%A8%E9%87%8A"><span class="nav-number">8.</span> <span class="nav-text">8. 注释</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#8-1-%E6%A0%87%E5%87%86%E6%B3%A8%E9%87%8A"><span class="nav-number">8.1.</span> <span class="nav-text">8.1 标准注释</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#8-1-1-%E5%8D%95%E8%A1%8C%E6%B3%A8%E9%87%8A"><span class="nav-number">8.1.1.</span> <span class="nav-text">8.1.1 单行注释</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#8-1-2-%E5%A4%9A%E8%A1%8C%E6%B3%A8%E9%87%8A"><span class="nav-number">8.1.2.</span> <span class="nav-text">8.1.2 多行注释</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-2-%E8%A7%A3%E6%9E%90%E5%99%A8%E7%BA%A7%E6%B3%A8%E9%87%8A"><span class="nav-number">8.2.</span> <span class="nav-text">8.2 解析器级注释</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#8-2-1-%E5%8D%95%E8%A1%8C%E6%B3%A8%E9%87%8A%EF%BC%9A"><span class="nav-number">8.2.1.</span> <span class="nav-text">8.2.1 单行注释：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#8-2-2-%E5%A4%9A%E8%A1%8C%E6%B3%A8%E9%87%8A"><span class="nav-number">8.2.2.</span> <span class="nav-text">8.2.2 多行注释</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#9-%E5%86%85%E8%81%94%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="nav-number">9.</span> <span class="nav-text">9. 内联表达式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#9-1-%E2%80%A6"><span class="nav-number">9.1.</span> <span class="nav-text">9.1 [[…]]</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-2-%E2%80%A6"><span class="nav-number">9.2.</span> <span class="nav-text">9.2 [(…)]</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-3-th-inline"><span class="nav-number">9.3.</span> <span class="nav-text">9.3 th:inline</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#9-3-1-none"><span class="nav-number">9.3.1.</span> <span class="nav-text">9.3.1 none</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#9-3-2-text"><span class="nav-number">9.3.2.</span> <span class="nav-text">9.3.2 text</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#9-3-3-css"><span class="nav-number">9.3.3.</span> <span class="nav-text">9.3.3 css</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#9-3-4-javascript"><span class="nav-number">9.3.4.</span> <span class="nav-text">9.3.4 javascript</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="王增明"
      src="/images/avatar.jpeg">
  <p class="site-author-name" itemprop="name">王增明</p>
  <div class="site-description" itemprop="description">喜欢折腾的极客聚集地.</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">23</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">18</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3dhbnplbmdtaW5n" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;wanzengming"><i class="fab fa-github fa-fw"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <a href="/wangzengming@aliyun.com" title="E-Mail → wangzengming@aliyun.com"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">王增明</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">342k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">5:11</span>
</div>

        
<div class="busuanzi-count">
  <script data-pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/pjax/pjax.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>

<script src="/js/bookmark.js"></script>

  <script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '#page-configurations',
    '.content-wrap',
    '.post-toc-wrap',
    '.languages',
    '#pjax'
  ],
  switches: {
    '.post-toc-wrap': Pjax.switches.innerHTML
  },
  analytics: false,
  cacheBust: false,
  scrollTo : !CONFIG.bookmark.enable
});

window.addEventListener('pjax:success', () => {
  document.querySelectorAll('script[data-pjax], script#page-configurations, #pjax script').forEach(element => {
    var code = element.text || element.textContent || element.innerHTML || '';
    var parent = element.parentNode;
    parent.removeChild(element);
    var script = document.createElement('script');
    if (element.id) {
      script.id = element.id;
    }
    if (element.className) {
      script.className = element.className;
    }
    if (element.type) {
      script.type = element.type;
    }
    if (element.src) {
      script.src = element.src;
      // Force synchronous loading of peripheral JS.
      script.async = false;
    }
    if (element.dataset.pjax !== undefined) {
      script.dataset.pjax = '';
    }
    if (code !== '') {
      script.appendChild(document.createTextNode(code));
    }
    parent.appendChild(script);
  });
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  NexT.utils.updateSidebarPosition();
});
</script>


  <script defer src="/lib/three/three.min.js"></script>
    <script defer src="/lib/three/three-waves.min.js"></script>
    <script defer src="/lib/three/canvas_lines.min.js"></script>
    <script defer src="/lib/three/canvas_sphere.min.js"></script>


  
  <script data-pjax>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>




  
<script src="/js/local-search.js"></script>











<script data-pjax>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js', () => {
    mermaid.initialize({
      theme    : 'forest',
      logLevel : 3,
      flowchart: { curve     : 'linear' },
      gantt    : { axisFormat: '%m/%d/%Y' },
      sequence : { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script>


    <div id="pjax">
  

  

    </div>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","model":{"jsonPath":"/live2dw/assets/hijiki.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":false},"react":{"opacityDefault":1,"opacityOnHover":1},"log":false,"tagMode":false});</script></body>
</html>
<script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>
